/**
 * 封装为请求类
 */
class HttpRequest {
    constructor(url,reqBody,method,timeout,fun){
        this.httpRequest=new XMLHttpRequest();
        this.httpRequest.fun=fun;
        this.url=url;
        this.reqBody=reqBody;
        this.method=method;
        this.timeout=timeout;
    };
    cancle=()=>{
        this.httpRequest.abort();
    }
    request=()=>{
        this.httpRequest.onreadystatechange=function(e){
            if (e.currentTarget.readyState===4 ){
                this.fun(e.currentTarget.status,e.currentTarget.responseText,JSON.parse(e.currentTarget.responseText));
            }
        };
        this.httpRequest.timeout=this.timeout;
        this.httpRequest.open(this.method,this.url,true);
        this.httpRequest.setRequestHeader("Content-Type","application/json");
        this.httpRequest.send(this.reqBody);
    }
}